package hh;

import hh.engine.Engine;
import hh.engine.Table;
import hh.util.CommonUtil;
import hh.util.coll.CollUtil;
import org.apache.jasper.JspC;

import java.util.Date;
import java.util.List;

public class Demo {
    public static void main(String[] args) throws Exception {
        Engine engine = new Engine();
        engine.setSourceDir(CommonUtil.getClassPath(Demo.class));
        engine.setOutputDir(CommonUtil.getResourcesPath(Demo.class));
        engine.setTemplateFiles("template/entity.jsp");
        engine.setDebugEnable(true);

        Table t1 = new Table("student", "学生表").setColumns(
                CollUtil.newArrayList(
                        new Column("name", "varchar", "学生姓名", String.class),
                        new Column("score", "bigdecimal", "学生分数", Double.class),
                        new Column("age", "tinyint", "学生年龄", int.class)
                )
        );
        Table t2 = new Table("member", "会员表").setColumns(
                CollUtil.newArrayList(
                        new Column("phone", "varchar", "手机号", String.class),
                        new Column("created_time", "datetime", "创建时间", Date.class),
                        new Column("username", "varchar", "用户名", String.class)
                )
        );
        List<Table> tables = CommonUtil.newArrayList(t1, t2);
        engine.setTables(tables);
        engine.execute();
    }

    /*

     */

    public static String jspcTest() {
        String error = "";
        try {
            JspC jspc = new JspC();
            //第一种方式
            //String[] arg0 = {"-uriroot", "F:/apache-tomcat-6.0.43/webapps/ROOT", "-d", "F:/test",
            //                    "index.jsp" };
            //            jspc.setArgs(arg0);
            //第二种方式
            jspc.setUriroot("C:\\Users\\Deepexi\\Desktop\\deepe\\learning\\mybatis\\mybatis-generator\\src\\main\\resources");//web应用的root目录
            jspc.setOutputDir("C:\\Users\\Deepexi\\Desktop\\deepe\\learning\\mybatis\\mybatis-generator\\src\\main\\resources");//.java文件和.class文件的输出目录
            jspc.setJspFiles("abc.jsp");//要编译的jsp

            jspc.setCompile(true);//是否编译 false或不指定的话只生成.java文件
            jspc.execute();
        } catch (Exception e) {
            error = e.toString();
        }
        return error;
    }
}
